package com.orangelife.mobile.guide.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.common.jump.CommonJumper;
import com.curry.orangelife.mobile.R;

@SuppressLint("ValidFragment")
public class GuideFragment4 extends Fragment {

	private View homePageView;
	private ImageView ivGuide;
	private int w = 0;
	private Button btnStart;
	private FinishListener listener;

	public GuideFragment4(int w) {
		this.w = w;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (homePageView == null) {
			homePageView = inflater.inflate(R.layout.fragment_gui_4, container,
					false);
			initView();
		}
		/**
		 * 缓存的viewiew需要判断是否已经被加过parent，
		 * 如果有parent需要从parent删除，要不然会发生这个view已经有parent的错误。
		 */
		ViewGroup parent = (ViewGroup) homePageView.getParent();
		if (parent != null) {
			parent.removeView(homePageView);
		}

		return homePageView;
	}

	private void initView() {
//		ivGuide = (ImageView) homePageView.findViewById(R.id.iv_guide);
		btnStart = (Button) homePageView.findViewById(R.id.btnStart);
//		float imgW = 1f;
//		float imgH = 1.2f;
//		float width = w / 1.3f;
//		LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(
//				(int) (width * imgW), (int) (width * imgH));
//		ivGuide.setLayoutParams(mParams);
//		width = w / 2;
//		imgW = 3.5f;
//		imgH = 1f;
//		LinearLayout.LayoutParams Params = new LinearLayout.LayoutParams(
//				(int) (width), (int) (width / imgW));
//		btnStart.setLayoutParams(Params);
		btnStart.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
//				Intent intent = new Intent();
////				intent.putExtra("back", "guide");
//				intent.setClass(getActivity(), Login3Activity.class);
//				startActivity(intent);
				CommonJumper.jumpToLogin(getActivity());
				listener.onFinished();
			}
		});
	}
	
	public void setFinishListener(FinishListener listener){
		this.listener=listener;
	}
	
	public interface FinishListener {
		void onFinished();
	}
}
